from django.db import models
from utils.basemodel import BaseModel
from user.models import UserModel
from crouse.models import CrouseDeskModel
# Create your models here.
class CouponModel(models.Model):
    name = models.CharField(max_length=50,verbose_name="优惠券名称")
    price = models.IntegerField(verbose_name="优惠券金额")
    start_time = models.DateTimeField(verbose_name="开始时间")
    end_time = models.DateTimeField(verbose_name="结束时间")
    condition = models.CharField(max_length=100,default="",null=True)
    number = models.IntegerField(verbose_name="数量",null=True,default=10)
    type = models.CharField(max_length=100,verbose_name="类型",default="满减")
    class Meta:
        db_table = "coupon"
    def __str__(self):
        return self.name
class UserCoupon(BaseModel):
    user = models.ForeignKey(UserModel,on_delete=models.CASCADE,verbose_name="所属用户")
    coupon = models.ForeignKey(CouponModel,on_delete=models.CASCADE,verbose_name="优惠券")
    class Meta:
        db_table = "fgusercoupon"
class OrderModel(BaseModel):
    user = models.ForeignKey(UserModel,on_delete=models.CASCADE,verbose_name="所属用户")
    orderno = models.CharField(max_length=100,verbose_name="订单号")
    totalprice = models.DecimalField(max_digits=10,decimal_places=2,verbose_name="订单总价")
    payprice = models.DecimalField(max_digits=10,decimal_places=2,verbose_name="支付金额")
    status = models.IntegerField(verbose_name="订单状态",choices=((0,'未支付'),(1,"已支付"),(2,'已取消'),(3,'已完成')),default=0)
    score = models.IntegerField(verbose_name='积分',default=0)
    coupon=models.IntegerField(verbose_name='优惠券',null=True,blank=True)
    paytype = models.IntegerField(verbose_name='支付方式',choices=((0,'支付宝'),(1,'微信'),(2,'银行卡')),default=0)
    paytime= models.DateTimeField(verbose_name='支付时间',null=True,blank=True)
    payno = models.CharField(verbose_name='支付流水号',max_length=100,null=True,blank=True)
    class  Meta:
        db_table = "order"
    def __str__(self):
        return self.orderno

class OrderDetial(models.Model):
    order = models.ForeignKey(OrderModel,on_delete=models.CASCADE,verbose_name='订单')
    course  = models.ForeignKey(CrouseDeskModel,on_delete=models.CASCADE,verbose_name='课程')
    cname  = models.CharField(max_length=100,verbose_name='课程名称')
    price  = models.DecimalField(max_digits=10,decimal_places=2,verbose_name='课程价格')
    discount  = models.DecimalField(max_digits=10,decimal_places=2,verbose_name='折扣')
    ccover  = models.CharField(max_length=100,verbose_name='封面')

    class Meta:
        db_table = "order_detial"
    def __str__(self):
        return self.order




